/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.view.base;

import java.awt.FileDialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.File;

import javax.swing.JFrame;
import javax.swing.JPanel;

import com.ruipengkj.commons.util.Util;
import com.ruipengkj.component.WaitComponent;
import com.ruipengkj.factory.UIFactory;

public abstract class BasePanel extends JPanel implements MouseMotionListener,MouseListener,ActionListener,KeyListener{
	
	private static final long serialVersionUID = 1L;
	protected UIFactory uiFactory;//创建UI工厂
	
	//等待组件
	protected WaitComponent waitComponent=WaitComponent.getInstance();
	
	public BasePanel(){
		uiFactory=UIFactory.getInstance();
		this.setOpaque(false);
//		ApplicationContext.CardUtilThread.setFlag(false);//停止之前线程
	}
	
	@Override
	public void mouseDragged(MouseEvent arg0) {
	
	}

	@Override
	public void mouseMoved(MouseEvent arg0) {
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
	}

	@Override
	public void mouseExited(MouseEvent e) {
	}

	@Override
	public void mousePressed(MouseEvent e) {
	}

	@Override
	public void mouseReleased(MouseEvent e) {
	}

	@Override
	public void actionPerformed(ActionEvent e) {
	}
	
	@Override
	public void keyPressed(KeyEvent e) {
		
	}

	@Override
	public void keyReleased(KeyEvent e) {
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		
	}
	//浏览图片
	protected String getFileDialogFilePath(int kb){
		FileDialog fileDialog=new FileDialog(new JFrame(),"浏览图片");
		fileDialog.setVisible(true);
		String fileDir=fileDialog.getDirectory();
		String fileName=fileDialog.getFile();
		if(fileDir!=null&&!fileDir.equals("")&&fileName!=null&&!fileName.equals("")){
			if(fileName.toLowerCase().trim().endsWith(".jpg")||fileName.toLowerCase().trim().endsWith(".png")){
				File file=new File(fileDir+fileName);
				if(file.length()>(kb*1024)){
					Util.showMessageDialog("图片大小不能大于"+kb+"KB");
				}else{
					return fileDir+fileName;
				}
			}else{
				Util.showMessageDialog("图片格式只支持JPG/PNG");
			}
		}
		return null;
	}
	
	public abstract void clear();
}
